# 加载django的环境
import os

# 如果不想把celery_task包放在项目根目录下，必须添加下面两句,将项目根目录要添加到环境变量中
# 因为加载django环境需要加载dev
# import sys
# sys.path.append(r'F:\luffy\luffyapi')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "luffyapi.settings.dev")
# import django
# django.setup()

from celery import Celery

broker = 'redis://127.0.0.1:6379/1'
backend = 'redis://127.0.0.1:6379/2'

app = Celery(broker=broker,backend=backend,include=['celery_task.tasks'])

# 时区
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False

# 任务的定时配置
'''
app.conf.beat_schedule = {
    '自定义定时任务名': {
        'task': '指向任务函数',
        'schedule': '下一次再添加任务的时间间隔或固定的时间配置',
        'args': '无名参数',
        'kwargs': '有名参数'
    }
}
'''

from datetime import timedelta
from celery.schedules import crontab
app.conf.beat_schedule = {
    'update-banner-list': {
        'task': 'celery_task.tasks.update_banner_list',
        'schedule': timedelta(seconds=10),
        # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
        'args': (),
    }
}